home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / pmathlib / pmlsrc21.zoo / pmlsrc / floor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.3 KB  |  81 lines

  1. /*
  2.  * floor and ceil
  3.  *     from pete housels posting
  4.  */
  5.  
  6. #if !defined (__M68881__) || !defined (sfp004)
  7. #if __STDC__
  8. double    modf(double, double *);
  9. #else
  10. double    modf();
  11. #endif
  12.  
  13. double
  14. floor(double x)
  15. {
  16.  double fract;
  17.  
  18.  fract = modf(x, &x);
  19.  
  20.  if(fract < 0.0)
  21.     return x - 1.0;
  22.  else
  23.     return x;
  24. }
  25.  
  26. double
  27. ceil(double x)
  28. {
  29.     return(-floor(-x));
  30. }
  31. #endif
  32.  
  33. #ifdef __M68881_
  34.  
  35. double ceil (double x)
  36. {
  37.   int rounding_mode, round_up;
  38.   double value;
  39.  
  40.   __asm volatile ("fmove%.l fpcr,%0"
  41.           : "=dm" (rounding_mode)
  42.           : /* no inputs */ );
  43.   round_up = rounding_mode | 0x30;
  44.   __asm volatile ("fmove%.l %0,fpcr"
  45.           : /* no outputs */
  46.           : "dmi" (round_up));
  47.   __asm volatile ("fint%.x %1,%0"
  48.           : "=f" (value)
  49.           : "f" (x));
  50.   __asm volatile ("fmove%.l %0,fpcr"
  51.           : /* no outputs */
  52.           : "dmi" (rounding_mode));
  53.   return value;
  54. }
  55.  
  56. double floor (double x)
  57. {
  58.   int rounding_mode, round_down;
  59.   double value;
  60.  
  61.   __asm volatile ("fmove%.l fpcr,%0"
  62.           : "=dm" (rounding_mode)
  63.           : /* no inputs */ );
  64.   round_down = (rounding_mode & ~0x10)
  65.         | 0x20;
  66.   __asm volatile ("fmove%.l %0,fpcr"
  67.           : /* no outputs */
  68.           : "dmi" (round_down));
  69.   __asm volatile ("fint%.x %1,%0"
  70.           : "=f" (value)
  71.           : "f" (x));
  72.   __asm volatile ("fmove%.l %0,fpcr"
  73.           : /* no outputs */
  74.           : "dmi" (rounding_mode));
  75.   return value;
  76. }
  77. #endif __M68881__
  78.  
  79. #ifdef    sfp004
  80. #endif    sfp004
  81.